package com.pdool.game.service;

import com.pdool.game.dao.ApiUserEntityDao;
import com.pdool.game.entity.ApiUserEntity;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service

@CacheConfig(cacheNames = "users")
public class UserService {
    @Resource
    ApiUserEntityDao apiUserEntityDao;

    @Cacheable(key = "#root.methodName")
    public List<ApiUserEntity> queryUser(){
        List<ApiUserEntity> all = apiUserEntityDao.findAll();

        return all;
    }
    @CachePut(key = "#result.userId")
    public ApiUserEntity cacheItem(ApiUserEntity entity){
        return entity;
    }

    @Cacheable(key = "#userId")
    public ApiUserEntity queryUserOne(Integer userId){
        return apiUserEntityDao.getOne(userId);
    }
}
